currentTs <- Sys.time()
library(ggplot2)
library(dplyr)
library(stringr)
library(scales)
library(patchwork)
library(ggrepel)
library(data.table)

getTime <- function() {
  Sys.time() - currentTs
}
library(optparse)

option_list <- list(
  make_option("--i", default = "", type = "character", help = "input file"),
  make_option("--c", default = "", type = "character", help = "color file"),
  make_option("--s", default = "", type = "character", help = "gene sample"),
  make_option("--o", default = "", type = "character", help = "output pdf file")
)
opt <- parse_args(OptionParser(option_list = option_list))


exp.gene<-fread(opt$i) %>%
  as.data.frame()
pal1<-read.table(opt$c)[,1] %>%
  as.character()

symbol<-opt$s

pal1

#plot boxplot
p2.1<-ggplot(exp.gene,aes(x=celltype))+geom_boxplot(
  aes(ymin=Min,lower=Q25,middle=Med,upper=Q75,ymax=Max,color=celltype),
  stat = "identity",size=1
)+scale_color_manual(values = pal1)+
  labs(x=symbol,y=paste(symbol,'Expr.',sep = ' '))+
  theme_light()+theme(axis.title.x = element_blank(),axis.text.x = element_text(angle = 45,hjust = 1,vjust = 1))+
  theme(legend.position = 'none',axis.title = element_text(face = 'bold'),plot.title = element_text(hjust = 0.5,face = 'bold'))
p2.1

#plot dotplot
p2.2<-ggplot(data=exp.gene,aes(x=celltype,y=gene))+geom_point(aes(size = Freq,color = AvgExpr))+
  scale_color_gradient(low="lightgrey",high="blue")+theme_light()+theme(panel.grid.major  = element_blank())+
  theme(axis.title = element_blank(),axis.ticks = element_blank(),axis.text = element_blank(),legend.position = 'none')
p2.2

#patchwork
p2<-p2.2/p2.1+plot_layout(heights = c(1,8))
p2
ggsave(plot=p2,file=opt$o,width = 8,height = 6)
getTime()
